/**
 * 
 */
package com.scpii.universal.hibernate.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.hibernate.dao.ClientUserDao;
import com.scpii.universal.hibernate.entity.ClientUserTab;

/**
 * genericWeb
 * 
 * @author weny 2012-7-6上午10:49:27
 */
@Repository
public class ClientUserDaoImpl extends BaseDaoImpl<ClientUserTab, Integer>
		implements ClientUserDao {

	@Override
	public ClientUserTab getUserByLoginName(String name, int appId) {
		String hql = "from ClientUserTab c where c.varUserPhonenum=? and c.intDeleteSign=? "
				+ "and c.intAppId=?";
		@SuppressWarnings("unchecked")
		List<ClientUserTab> users = getHibernateTemplate().getSessionFactory()
				.getCurrentSession().createQuery(hql).setParameter(0, name)
				.setParameter(1, GenericConstants.DELETE_SIGN_EXIST)
				.setParameter(2, appId).list();
		if (users == null || users.size() <= 0) {
			return null;
		} else {
			return users.get(0);
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ClientUserTab> getAllUserByAppId(int appId) {
		String hql = "select new ClientUserTab(c.intUserId,c.varUserPhonenum) from ClientUserTab c where c.intDeleteSign=? and c.intAppId=?";
		return getHibernateTemplate().getSessionFactory().getCurrentSession()
				.createQuery(hql)
				.setParameter(0, GenericConstants.DELETE_SIGN_EXIST)
				.setParameter(1, appId).list();
	}

}
